import java.util.Random;
import java.util.Scanner;

class Computer {
    private String computerName;
    private String computerMethod;
    static int winTimes = 0;

    public void setComputerName(int num) {
        switch (num) {
            case 1:
                computerName = "曹操";
                break;
            case 2:
                computerName = "刘备";
                break;
            case 3:
                computerName = "孙权";
                break;
            default:
                computerName = "未知对手";
        }
    }

    public String getComputerName() {
        return computerName;
    }

    public String getComputerMethod() {
        Random random = new Random();
        int choice = random.nextInt(3);
        String[] methods = {"石头", "剪刀", "布"};
        computerMethod = methods[choice];
        return computerMethod;
    }
}

class Player {
    private String playerName;
    private String playerMethod;
    static int winTimes = 0;

    public String getPlayerName() {
        return playerName;
    }

    public void setPlayerName(String playerName) {
        this.playerName = playerName;
    }

    public String getPlayerMethod(int num) {
        String[] methods = {"石头", "剪刀", "布"};
        if (num >= 1 && num <= 3) {
            playerMethod = methods[num - 1];
        } else {
            System.out.println("出拳非法~");
            System.exit(-1);
        }
        return playerMethod;
    }
}

class GamePlatform {
    private Computer mComputer;
    private Player mPlayer;
    private Scanner scanner;

    private void beginningShow() {
        System.out.println("——————欢迎进入游戏世界——————");
        System.out.println("********************");
        System.out.println("***猜拳开始***");
        System.out.println("出拳规则：1.石头  2.剪刀  3.布");
    }

    private void gameStart() {
        scanner = new Scanner(System.in);
        System.out.print("请输入姓名：");
        String playerName = scanner.nextLine();
        mPlayer = new Player();
        mPlayer.setPlayerName(playerName);

        System.out.print("请选择对手<1-曹操  2-刘备  3-孙权>:");
        int choice = scanner.nextInt();
        mComputer = new Computer();
        mComputer.setComputerName(choice);

        System.out.print("要开始吗？(y/n):");
        String start = scanner.next();
        if (!"y".equalsIgnoreCase(start)) {
            System.out.println("游戏取消");
            System.exit(0);
        }
    }

    private void gameProceed() {
        while (true) {
            System.out.print("请输入你要出的拳<1-石头, 2-剪刀, 3-布>:");
            int playerChoice = scanner.nextInt();
            String playerMethod = mPlayer.getPlayerMethod(playerChoice);
            String computerMethod = mComputer.getComputerMethod();

            System.out.println("你出拳：" + playerMethod);
            System.out.println(mComputer.getComputerName() + "出拳" + computerMethod);

            if (playerMethod.equals(computerMethod)) {
                System.out.println("平局");
            } else if ((playerMethod.equals("石头") && computerMethod.equals("剪刀")) ||
                    (playerMethod.equals("剪刀") && computerMethod.equals("布")) ||
                    (playerMethod.equals("布") && computerMethod.equals("石头"))) {
                System.out.println(mPlayer.getPlayerName() + "赢了");
                Player.winTimes++;
            } else {
                System.out.println(mComputer.getComputerName() + "赢了");
                Computer.winTimes++;
            }

            System.out.print("是否继续？(y/n):");
            String continueStr = scanner.next();
            if (!"y".equalsIgnoreCase(continueStr)) {
                break;
            }
        }
    }

    private void gameEnd() {
        System.out.println("——————————结果——————————");
        System.out.println("***  " + mPlayer.getPlayerName() + " ：" + mComputer.getComputerName() + "  ***");
        System.out.println("——————————比分——————————");
        System.out.println("*************  " + Player.winTimes + " ：" + Computer.winTimes + "  *************");
        if (Player.winTimes > Computer.winTimes) {
            System.out.println("恭喜你赢了！");
        } else if (Player.winTimes < Computer.winTimes) {
            System.out.println("很遗憾，你输了！");
        } else {
            System.out.println("平局结束游戏！");
        }
        scanner.close();
    }

    public void algorithmProceed() {
        beginningShow();
        gameStart();
        gameProceed();
        gameEnd();
    }
}

public class Game {
    public static void main(String[] args) {
        GamePlatform gamePlatform = new GamePlatform();
        gamePlatform.algorithmProceed();
    }
}